package com.chilly.other.jdk8.Interface;

import org.junit.Test;

//定义一个函数式接口
@FunctionalInterface
interface Agreeable {
    void greet();
}

//定义一个父类
class Human {
    public void hello() {
        System.out.println("hello my sun !");
    }
}

/**
 * @project: jdk-learnig
 * @description: 通过Supper引用父类中的成员方法
 * @author: 黄宇辉
 * @date: 8/18/2019-4:06 PM
 * @version: 1.0
 * @website: https://yubuntu0109.github.io/
 */
public class RefMethodBySupper extends Human {

    @Override
    public void hello() {
        System.out.println("hello my father !");
    }

    public void printResult(Agreeable agreeable) {
        agreeable.greet();
    }

    //传统写法
    @Test
    public void testPrintResult() {
        printResult(new Agreeable() {
            @Override
            public void greet() {
                RefMethodBySupper.super.hello();
            }
        });
    }

    //Lambda表达式写法
    @Test
    public void testPrintResultWithLambda() {
        printResult(() -> super.hello());
    }

    //方法引用写法
    @Test
    public void testPrintResultWithMethodRef() {
        printResult(super::hello);
    }

}